package com.hsylient.javase.chapter05;

import java.io.*;

/**
 * 文件的拷贝
 */
public class C_FileCopy {
    public static void main(String[] args) {
        File resource = new File("D:\\IdeaProjects\\logger\\log\\JULCustomProperties.txt");
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            fileInputStream = new FileInputStream(resource);
            fileOutputStream = new FileOutputStream("JULCustomProperties.txt", Boolean.TRUE);
            byte[] bytes = new byte[8];
            int readLen;
            while ((readLen = fileInputStream.read(bytes)) != -1) {
                fileOutputStream.write(bytes, 0, readLen);
            }
            fileOutputStream.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
